package com.androidx.p013lv.mine.fragment;

import android.os.Bundle;
import android.view.View;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.androidx.p013lv.base.bean.VideoHistory;
import com.androidx.p013lv.base.listener.ItemClickListener;
import com.androidx.p013lv.base.p015ui.LazyFragment;
import com.androidx.p013lv.base.utils.SpUtils;
import com.androidx.p013lv.base.utils.UiUtils;
import com.androidx.p013lv.base.view.StatusControlLayout;
import com.androidx.p013lv.mine.C1207R;
import com.androidx.p013lv.mine.adapter.MineHistoryVideoAdapter;
import com.androidx.p013lv.mine.databinding.FragmentMineHistoryVideoLayoutBinding;
import com.androidx.p013lv.mine.model.MineHistoryModel;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;
import com.yanzhenjie.recyclerview.OnItemMenuClickListener;
import com.yanzhenjie.recyclerview.SwipeMenu;
import com.yanzhenjie.recyclerview.SwipeMenuBridge;
import com.yanzhenjie.recyclerview.SwipeMenuCreator;
import com.yanzhenjie.recyclerview.SwipeMenuItem;
import com.yanzhenjie.recyclerview.SwipeRecyclerView;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/* renamed from: com.androidx.lv.mine.fragment.MineHistoryVideoFragment */
public class MineHistoryVideoFragment extends LazyFragment<FragmentMineHistoryVideoLayoutBinding> implements OnRefreshLoadMoreListener, ItemClickListener {
    private MineHistoryVideoAdapter adapter;
    private RecyclerView.AdapterDataObserver dataObserver = new RecyclerView.AdapterDataObserver() {
        /* class com.androidx.p013lv.mine.fragment.MineHistoryVideoFragment.C13181 */

        @Override // androidx.recyclerview.widget.RecyclerView.AdapterDataObserver
        public void onChanged() {
            MineHistoryVideoFragment.this.deleteChangeState();
        }

        @Override // androidx.recyclerview.widget.RecyclerView.AdapterDataObserver
        public void onItemRangeChanged(int i, int i2) {
            MineHistoryVideoFragment.this.deleteChangeState();
        }
    };
    private boolean isEdit;
    private Long lastId = 0L;
    OnItemMenuClickListener mItemMenuClickListener = new OnItemMenuClickListener() {
        /* class com.androidx.p013lv.mine.fragment.MineHistoryVideoFragment.C13225 */

        @Override // com.yanzhenjie.recyclerview.OnItemMenuClickListener
        public void onItemClick(SwipeMenuBridge swipeMenuBridge, int i) {
            swipeMenuBridge.closeMenu();
            MineHistoryVideoFragment.this.deleteSingleCollect(i);
        }
    };
    SwipeMenuCreator mSwipeMenuCreator = new SwipeMenuCreator() {
        /* class com.androidx.p013lv.mine.fragment.MineHistoryVideoFragment.C13214 */

        @Override // com.yanzhenjie.recyclerview.SwipeMenuCreator
        public void onCreateMenu(SwipeMenu swipeMenu, SwipeMenu swipeMenu2, int i) {
            SwipeMenuItem swipeMenuItem = new SwipeMenuItem(MineHistoryVideoFragment.this.getActivity());
            swipeMenuItem.setBackgroundColorResource(C1207R.C1208color.mainColor);
            swipeMenuItem.setWidth(UiUtils.dp2px(70));
            swipeMenuItem.setHeight(-1);
            swipeMenuItem.setTextSize(16);
            swipeMenuItem.setText("刪除");
            swipeMenuItem.setTextColorResource(C1207R.C1208color.white);
            swipeMenu2.setOrientation(1);
            swipeMenu2.addMenuItem(swipeMenuItem);
        }
    };
    private MineHistoryModel model;

    public static MineHistoryVideoFragment newInstance() {
        Bundle bundle = new Bundle();
        bundle.putString("", "");
        MineHistoryVideoFragment mineHistoryVideoFragment = new MineHistoryVideoFragment();
        mineHistoryVideoFragment.setArguments(bundle);
        return mineHistoryVideoFragment;
    }

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public int setFragmentView() {
        return C1207R.C1212layout.fragment_mine_history_video_layout;
    }

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public void initViews() {
        this.model = (MineHistoryModel) new ViewModelProvider(this).get(MineHistoryModel.class);
        ((FragmentMineHistoryVideoLayoutBinding) this.binding).setIsEdit(Boolean.valueOf(this.isEdit));
        ((FragmentMineHistoryVideoLayoutBinding) this.binding).setSelectNum(0);
        ((FragmentMineHistoryVideoLayoutBinding) this.binding).recycler.setPadding(0, UiUtils.dp2px(20), 0, 0);
        ((FragmentMineHistoryVideoLayoutBinding) this.binding).recycler.setSwipeMenuCreator(this.mSwipeMenuCreator);
        ((FragmentMineHistoryVideoLayoutBinding) this.binding).recycler.setOnItemMenuClickListener(this.mItemMenuClickListener);
        MineHistoryVideoAdapter mineHistoryVideoAdapter = new MineHistoryVideoAdapter();
        this.adapter = mineHistoryVideoAdapter;
        mineHistoryVideoAdapter.setItemListener(this);
        ((FragmentMineHistoryVideoLayoutBinding) this.binding).recycler.setLayoutManager(new LinearLayoutManager(getActivity()));
        ((FragmentMineHistoryVideoLayoutBinding) this.binding).recycler.setAdapter(this.adapter);
        this.adapter.registerAdapterDataObserver(this.dataObserver);
        ((FragmentMineHistoryVideoLayoutBinding) this.binding).statusLayout.setOnRetryListener(new View.OnClickListener() {
            /* class com.androidx.p013lv.mine.fragment.MineHistoryVideoFragment.View$OnClickListenerC13192 */

            public void onClick(View view) {
                MineHistoryVideoFragment.this.lastId = 0L;
                ((FragmentMineHistoryVideoLayoutBinding) MineHistoryVideoFragment.this.binding).setStatus(2);
                MineHistoryVideoFragment.this.model.getHistoryVideo(MineHistoryVideoFragment.this.lastId);
            }
        });
        ((FragmentMineHistoryVideoLayoutBinding) this.binding).refresh.setOnRefreshListener(this);
        ((FragmentMineHistoryVideoLayoutBinding) this.binding).refresh.setOnLoadMoreListener(this);
        this.model.data().observe(this, new Observer<List<VideoHistory>>() {
            /* class com.androidx.p013lv.mine.fragment.MineHistoryVideoFragment.C13203 */

            public void onChanged(List<VideoHistory> list) {
                MineHistoryVideoFragment.this.hideLoading();
                if (MineHistoryVideoFragment.this.lastId.longValue() == 0) {
                    if (list == null || list.size() == 0) {
                        ((FragmentMineHistoryVideoLayoutBinding) MineHistoryVideoFragment.this.binding).setStatus(4);
                        return;
                    }
                    MineHistoryVideoFragment.this.adapter.setDomain(SpUtils.getInstance().getString("domain"));
                    MineHistoryVideoFragment.this.adapter.setData(list);
                    if (list.size() < 30) {
                        ((FragmentMineHistoryVideoLayoutBinding) MineHistoryVideoFragment.this.binding).setStatusRefresh(2);
                    }
                } else if (list == null || list.size() == 0) {
                    ((FragmentMineHistoryVideoLayoutBinding) MineHistoryVideoFragment.this.binding).setStatusRefresh(2);
                } else {
                    MineHistoryVideoFragment.this.adapter.setDatasInEnd(list);
                    if (list.size() < 30) {
                        ((FragmentMineHistoryVideoLayoutBinding) MineHistoryVideoFragment.this.binding).setStatusRefresh(2);
                    }
                }
            }
        });
        ((FragmentMineHistoryVideoLayoutBinding) this.binding).setStatus(2);
        this.model.getHistoryVideo(this.lastId);
    }

    @Override // com.scwang.smartrefresh.layout.listener.OnLoadMoreListener
    public void onLoadMore(RefreshLayout refreshLayout) {
        if (this.adapter.getLastDataInPosition() == null) {
            ((FragmentMineHistoryVideoLayoutBinding) this.binding).setStatusRefresh(2);
            return;
        }
        Long id = ((VideoHistory) this.adapter.getLastDataInPosition()).getId();
        this.lastId = id;
        this.model.getHistoryVideo(id);
    }

    @Override // com.scwang.smartrefresh.layout.listener.OnRefreshListener
    public void onRefresh(RefreshLayout refreshLayout) {
        this.lastId = 0L;
        this.model.getHistoryVideo(0L);
    }

    @Override // com.androidx.p013lv.base.listener.ItemClickListener
    public void onItemClick(View view, int i) {
        if (!this.isEdit) {
            startVideoPlay(((VideoHistory) this.adapter.getDataInPosition(i)).getVideoId());
            return;
        }
        VideoHistory videoHistory = (VideoHistory) this.adapter.getDataInPosition(i);
        int i2 = 1;
        if (((VideoHistory) this.adapter.getDataInPosition(i)).getEditState() == 1) {
            i2 = 2;
        }
        videoHistory.setEditState(i2);
        this.adapter.notifyItemChanged(i, Integer.valueOf(C1207R.C1210id.img_select));
    }

    public void hideLoading() {
        ((FragmentMineHistoryVideoLayoutBinding) this.binding).setStatus(0);
        ((FragmentMineHistoryVideoLayoutBinding) this.binding).setStatusRefresh(1);
    }

    public static void showStatusView(StatusControlLayout statusControlLayout, int i) {
        statusControlLayout.showStatusView(i);
    }

    public static void refreshStatus(SmartRefreshLayout smartRefreshLayout, int i) {
        if (i == 1) {
            smartRefreshLayout.finishLoadMore();
            smartRefreshLayout.finishRefresh();
        }
        if (i == 2) {
            smartRefreshLayout.finishLoadMoreWithNoMoreData();
        }
    }

    public static void refreshEnabled(SmartRefreshLayout smartRefreshLayout, boolean z) {
        smartRefreshLayout.setEnableRefresh(!z);
        smartRefreshLayout.setEnableLoadMore(!z);
    }

    public static void isSwipeMenuList(SwipeRecyclerView swipeRecyclerView, boolean z) {
        swipeRecyclerView.setSwipeItemMenuEnabled(!z);
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void deleteChangeState() {
        if (this.isEdit) {
            int i = 0;
            for (int i2 = 0; i2 < this.adapter.getData().size(); i2++) {
                if (((VideoHistory) this.adapter.getData().get(i2)).getEditState() == 2) {
                    i++;
                }
            }
            ((FragmentMineHistoryVideoLayoutBinding) this.binding).setSelectNum(Integer.valueOf(i));
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void deleteCollectVideo() {
        ArrayList arrayList = new ArrayList();
        Iterator it = this.adapter.getData().iterator();
        while (it.hasNext()) {
            VideoHistory videoHistory = (VideoHistory) it.next();
            if (videoHistory.getEditState() == 2) {
                arrayList.add(videoHistory);
                it.remove();
            }
        }
        for (int i = 0; i < this.adapter.getData().size(); i++) {
            ((VideoHistory) this.adapter.getData().get(i)).setEditState(0);
        }
        this.adapter.notifyDataSetChanged();
        this.model.deleteVideoList(arrayList);
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void deleteSingleCollect(int i) {
        this.adapter.getData().remove(this.adapter.getData().get(i));
        this.adapter.notifyDataSetChanged();
        this.model.deleteVideoHistory((VideoHistory) this.adapter.getData().get(i));
    }

    @Override // androidx.fragment.app.Fragment, com.gyf.immersionbar.components.ImmersionFragment
    public void onDestroy() {
        this.adapter.unregisterAdapterDataObserver(this.dataObserver);
        super.onDestroy();
    }

    /* renamed from: com.androidx.lv.mine.fragment.MineHistoryVideoFragment$OnClick */
    public class OnClick {
        public OnClick() {
        }

        public void editCollect() {
            MineHistoryVideoFragment mineHistoryVideoFragment = MineHistoryVideoFragment.this;
            mineHistoryVideoFragment.isEdit = !mineHistoryVideoFragment.isEdit;
            ((FragmentMineHistoryVideoLayoutBinding) MineHistoryVideoFragment.this.binding).setIsEdit(Boolean.valueOf(MineHistoryVideoFragment.this.isEdit));
            if (MineHistoryVideoFragment.this.isEdit) {
                for (int i = 0; i < MineHistoryVideoFragment.this.adapter.getData().size(); i++) {
                    ((VideoHistory) MineHistoryVideoFragment.this.adapter.getData().get(i)).setEditState(1);
                }
                MineHistoryVideoFragment.this.adapter.notifyDataSetChanged();
                return;
            }
            for (int i2 = 0; i2 < MineHistoryVideoFragment.this.adapter.getData().size(); i2++) {
                ((VideoHistory) MineHistoryVideoFragment.this.adapter.getData().get(i2)).setEditState(0);
            }
            MineHistoryVideoFragment.this.adapter.notifyDataSetChanged();
        }

        public void allSelectedBtn() {
            for (int i = 0; i < MineHistoryVideoFragment.this.adapter.getData().size(); i++) {
                ((VideoHistory) MineHistoryVideoFragment.this.adapter.getData().get(i)).setEditState(2);
            }
            MineHistoryVideoFragment.this.adapter.notifyDataSetChanged();
        }

        public void deleteBtn() {
            MineHistoryVideoFragment.this.deleteCollectVideo();
            MineHistoryVideoFragment mineHistoryVideoFragment = MineHistoryVideoFragment.this;
            mineHistoryVideoFragment.isEdit = !mineHistoryVideoFragment.isEdit;
            ((FragmentMineHistoryVideoLayoutBinding) MineHistoryVideoFragment.this.binding).setIsEdit(Boolean.valueOf(MineHistoryVideoFragment.this.isEdit));
        }
    }
}
